home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11367 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  109 lines

  1. Path: news.mindspring.com!usenet
  2. From: rudd@mindspring.com (Justin Rudd)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Need help!
  5. Date: Thu, 14 Mar 1996 04:55:40 GMT
  6. Organization: MindSpring Enterprises
  7. Message-ID: <4i8922$4pi@firebrick.mindspring.com>
  8. References: <Do858A.Btr@iquest.net>
  9. Reply-To: rudd@mindspring.com
  10. NNTP-Posting-Host: rudd.mindspring.com
  11. X-Newsreader: Forte Free Agent v0.55
  12.  
  13. OK...sorry there are no > in front of what you originally posted
  14. because I played with the code a bit and reformatted to a form I could
  15. easily read :-)
  16.  
  17. Well anyway...I'll just inject my comments in the code below...
  18.  
  19. #include <dos.h>
  20. #include <stdlib.h>
  21. #include <math.h>
  22. #include <dir.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <conio.h>
  26.  
  27. struct data
  28.     char name[50];
  29. }; 
  30.  
  31. class reg 
  32. {
  33.       public:
  34.         void init(void);
  35.         void desc(struct data *dptr);
  36. };
  37.  
  38. void reg::init(void)
  39. {
  40. }
  41.  
  42. void reg::desc(struct data *dptr)
  43. {   
  44.     //First off you were using the pointer directly...
  45.     //I make it a practice to never do that...I always make a temp
  46.     //pointer.  
  47.     data* temp = NULL;
  48.  
  49.     temp = dptr;
  50.     
  51.     int y=0,x=0;
  52.       
  53.     for(y=0;y<25;y++)
  54.     {
  55.         for(x=0;x<=y;x++) 
  56.         {
  57.             strcat(temp->name,"A");
  58.         }
  59.  
  60.         printf("%s\n", temp->name );
  61.         temp++;
  62.         getch();
  63.     }
  64.  
  65.     /* Here is the problem area*/
  66.  
  67.     //With a temp pointer you don't even have to worry about going                 
  68.     //backwards you can just start you second loop with your parameter
  69.     //pointer dptr.
  70.     //for(y=0;y<25;y++) dptr--;
  71.        
  72.     for(y=0;y<25;y++)
  73.     {
  74.         printf("\n%4d %s",y,dptr->name);
  75.         // also in you original code...you never incremented dptr :-)
  76.         dptr++;
  77.         getch();
  78.     }
  79. }
  80.  
  81. int main(void)
  82. {
  83.     reg reg1;
  84.  
  85.     data rrdata[25];
  86.     data *rptr;
  87.     
  88.     memset(rrdata,0,sizeof(data)*25);
  89.  
  90.     reg1.init();
  91.  
  92.     rptr = rrdata;
  93.     
  94.     reg1.desc(rptr);
  95.  
  96.     for(int x=0;x<25;x++)
  97.     {
  98.         printf("\n%4d %s",x,rrdata[x].name);
  99.     }
  100.  
  101.     return 0;     
  102. }
  103.  
  104. Hope this helps...
  105.  
  106. Justin
  107.  
  108.